﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace System.Windows.Media.DirectShow.Filters
{
    internal class PinTeeOutputPin : BaseOutputPin
    {

        private AMMediaType[] _mediaTypes = new AMMediaType[] { new AMMediaType {
            MajorType = MediaMajorTypes.None,
            SubType = MediaSubTypes.None,
        }};

        private PinTee filter;
        private int pinNumber;

        public PinTeeOutputPin(PinTee filter, int pinNumber)
            : base(filter)
        {
            this.pinNumber = pinNumber;
            this.filter = filter;
        }

        protected override void Disconnect()
        {
            base.Disconnect();

            this.filter.Pins.Remove(this);
            if (this.filter.Pins.Count == 0)
                this.filter.AddNewOutputPin();
        }

        protected override void Connect(IPin receivePin, AMMediaType mediaType)
        {
            base.Connect(receivePin, mediaType);

            this.filter.AddNewOutputPin();
        }

        internal void SetMediaTypes(AMMediaType[] mediaTypes)
        {
            _mediaTypes = mediaTypes;
        }

        public override void ProcessSample(IMediaSample sample)
        {
            // Use orignal sample
            this.DeliverAsync(sample);
        }

        public override System.Collections.Generic.IEnumerable<AMMediaType> MediaTypes
        {
            get { return _mediaTypes; }
        }

        public override string Name
        {
            get { return "Infinite Pin Tee Filter Output pin " + pinNumber; }
        }
    }
}
